<?php

class Questionbank {

	function __construct() {}
	
	// All function about db such as insert/edit/delete
	
	function getAllQuestionsBank() {
		global $db;
		$sql = "SELECT * FROM questionbank";
		$result = $db->db_query($sql);
		if($result) {
			$rows = $db->db_fetchrowset($result);
			return $rows;
		} else return false;
	}
	function getAllQuestionsBankExceptAddAlready($testid) {
		global $db;
		$sql = "SELECT * FROM questionbank where QuestionBankID not in (select QuestionNo from testquestions where TestID = ".$testid." )";
		$result = $db->db_query($sql);
		if($result) {
			$rows = $db->db_fetchrowset($result);
			return $rows;
		} else return false;
	}
	function getQuestionBankDetail($qbid) {
		global $db;
		$sql = "SELECT * FROM questionbank WHERE QuestionBankID='".$qbid."'";
		$result = $db->db_query($sql);
		if($result) {
			$row = $db->db_fetchrow($result);
			return $row;
		} else return false;
	}
	function insert_Question_Bank($data) {
		global $db;
		$sql = "INSERT INTO questionbank(
				`QuestionBankID`,
				`Question`,
				`ModeAnswer`,
				`Answer`,
				`Mark`,
				`Option1`,
				`Option2`,
				`Option3`,
				`Option4`,
				`Option5`,
				`SystemAnswerOption1`,
				`SystemAnswerOption2`,
				`SystemAnswerOption3`,
				`SystemAnswerOption4`,
				`SystemAnswerOption5`,
				`Status`
			) VALUES(
				NULL,				
				'".$data['Question']."',
				'".$data['ModeAnswer']."',
				'".$data['Answer']."',
				".$data['Mark'].",
				'".$data['Option1']."',
				'".$data['Option2']."',
				'".$data['Option3']."',
				'".$data['Option4']."',
				'".$data['Option5']."',
				'".$data['SystemAnswerOption1']."',
				'".$data['SystemAnswerOption2']."',
				'".$data['SystemAnswerOption3']."',
				'".$data['SystemAnswerOption4']."',
				'".$data['SystemAnswerOption5']."',1)";
				//echo $sql;
		$result = $db->db_query($sql);
		if($result) {
			return true;
		} else return false;
	
	}
	function update_Question_Bank($data) {
		global $db;
		$sql = "UPDATE questionbank SET Question='".$data['Question']."', ModeAnswer='".$data['ModeAnswer'].
		"', Answer='".$data['Answer'].
		"', Mark=".$data['Mark'].
		", Option1='".$data['Option1'].
		"', Option2='".$data['Option2'].
		"', Option3='".$data['Option3'].
		"', Option4='".$data['Option4'].
		"', Option5='".$data['Option5'].
		"', SystemAnswerOption1='".$data['SystemAnswerOption1'].
		"', SystemAnswerOption2='".$data['SystemAnswerOption2'].
		"', SystemAnswerOption3='".$data['SystemAnswerOption3'].
		"', SystemAnswerOption4='".$data['SystemAnswerOption4'].
		"', SystemAnswerOption5='".$data['SystemAnswerOption5'].
		"', Status=".$data['Status']. 
		" WHERE QuestionBankID=".$data['QuestionBankID']."";
		
		$result = $db->db_query($sql);
		//echo $sql;
		if($result) {
			return true;
		} else return false;
	}
	function delete_question_bank($qbid) {
		global $db;
		$sql = "UPDATE questionbank SET Status=0 WHERE QuestionBankID=$qbid";
		$result = $db->db_query($sql);
		if($result) {
			return true;
		} else return false;
	}
	
	

}

?>